/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ufps.cuatro.util;

import com.ufps.cuatro.util.base.ObjectBase;
import java.util.ArrayList;

/**
 *
 * @author Carlos A. Torres C. 
 */
public class ModelColeccion extends ObjectBase {
    private static final long serialVersionUID = -1644328186319855951L;
    
    public static final int ERROR_VALUE_NUMBER_INTEGER = -99999;
    public static final double ERROR_VALUE_NUMBER_DOUBLE = -99999;
    public static final float ERROR_VALUE_NUMBER_FLOAT = -99999;
    public static final long ERROR_VALUE_NUMBER_LONG = -99999;
    public static final String ERROR_VALUE_NUMBER_STRING = "-99999";
    public static final char ERROR_VALUE_NUMBER_CHARACTER = '\0';
    
    private String strNombre;
    private String search;
    private boolean primitive;
    private boolean string;
    private ArrayList<ModelItemColeccion> objItems;
    
    public ModelColeccion(int id, String strNombre, String search, boolean primitive, boolean string) {
        super(id);
        this.strNombre = strNombre;
        this.search = search;
        this.primitive = primitive;
        this.string = string;
        this.objItems = new ArrayList<ModelItemColeccion>();
    }    

    public ArrayList<ModelItemColeccion> getObjItems() {
        return objItems;
    }

    public void setObjItems(ArrayList<ModelItemColeccion> objItems) {
        this.objItems = objItems;
    }

    public boolean isPrimitive() {
        return primitive;
    }

    public void setPrimitive(boolean primitive) {
        this.primitive = primitive;
    }

    public String getStrNombre() {
       try{
        return strNombre;
    }catch(java.lang.NullPointerException ex){}
       return "";
    }

    public void setStrNombre(String strNombre) {
        this.strNombre = strNombre;
    }

    public boolean isString() {
        return string;
    }

    public void setString(boolean string) {
        this.string = string;
    }

    public String getSearch() {
        return search;
    }

    public void setSearch(String search) {
        this.search = search;
    }
    
    public int getValueInteger(String NameOrValue, int valueDefault){        
        for(ModelItemColeccion objItem : this.objItems){
            if(objItem.getPropiedad().equalsIgnoreCase(NameOrValue)){
                try{
                    int number = Integer.parseInt(objItem.getValor());
                    return number;
                }catch(java.lang.NumberFormatException ex){
                    return valueDefault;            
                }
            }
        }
        try{
            int number = Integer.parseInt(NameOrValue);
            return number;
        }catch(java.lang.NumberFormatException ex){
            return valueDefault;
        }        
    }
    
    public double getValueDouble(String NameOrValue, double valueDefault){        
        for(ModelItemColeccion objItem : this.objItems){
            if(objItem.getPropiedad().equalsIgnoreCase(strNombre)){
                try{
                    double number = Double.parseDouble(objItem.getValor());
                    return number;
                }catch(java.lang.NumberFormatException ex){
                    return valueDefault;
                }
            }
        }
        try{
            double number = Double.parseDouble(NameOrValue);
            return number;
        }catch(java.lang.NumberFormatException ex){
            return valueDefault;
        }        
    }
}
